//
//  ELAnnotationDetailContentView.swift
//  WZApp
//
//  Created by evol on 2018/7/31.
//  Copyright © 2018年 evol. All rights reserved.
//

import UIKit

class ELAnnotationDetailContentView: UIView {
    init(text:String!,
         font: UIFont = UIFont.systemFont(ofSize: 15),
         textColor: UIColor = .black,
         space: CGFloat = 0,
         completion:(_ height: CGFloat) -> Void)
    {
        super.init(frame: .zero)
        var lastLeft:CGFloat = 0
        var maxHeight:CGFloat = 0
        let strings = text.components(separatedBy: "\n").reversed()
        for (index, string) in strings.enumerated() {
            let label = ELVerticalFormLabel(text: string, font: font, textColor: textColor, space: 0)
            addSubview(label)
            label.left = lastLeft == 0 ? 0 : lastLeft + space
            lastLeft = label.frame.maxX
            if index == strings.count - 1 {
                completion(label.frame.maxY)
            }
            if maxHeight < label.frame.height {
                maxHeight = label.frame.height
            }
        }
        self.height = maxHeight
        self.width = lastLeft
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
